#include <stdio.h>
#include <stdlib.h>

// 栈

#define MAXSIZE 15

typedef struct {
    int top;
    int data[MAXSIZE];
    
    int size;
} Stack;

void initStack(Stack *s) {
    s->top = -1;
    s->size = 0;
}

int isEmpty(Stack *s) {
    return s->top == -1;
}

int isFull(Stack *s) {
    return s->top == MAXSIZE - 1;
}

void push(Stack *s, int x) {
    if (isFull(s)) {
        printf("Stack is full.\n");
        return;
    }
    s->top++;
    s->data[s->top] = x;
    s->size++;
}

int pop(Stack *s) {
    if (isEmpty(s)) {
        printf("Stack is empty.\n");
        return -1;
    }
    int x = s->data[s->top];
    s->top--;
    s->size--;
    return x;
}

int peek(Stack *s) {
    if (isEmpty(s)) {   
        printf("Stack is empty.\n");
        return -1;
    }
    return s->data[s->top];
}

void printStack(Stack *s) {
    if (isEmpty(s)) {
        printf("Stack is empty.\n");
        return;
    }
    int i;
    for (i = s->top; i >= 0; i--) {
        printf("%d ", s->data[i]);
    }
    printf("\n");
}

int main() {
    Stack s;
    initStack(&s);
    push(&s, 1);
    push(&s, 2);
    push(&s, 3);
    push(&s, 4);
    push(&s, 5);
    push(&s, 6);
    push(&s, 7);
    push(&s, 8);
    push(&s, 9);
    push(&s, 10);
    push(&s, 11);
    
    push(&s, 12); // 栈满
    
    printf("Stack size: %d\n", s.size);
    printStack(&s);
    
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    pop(&s);
    
    printf("Stack size: %d\n", s.size);
    printStack(&s);
    
    return 0;
}       